﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PrinterClassDll;

namespace QFlow.Core
{
    public class BixolonPrinter : IPrinter
    {
        private static BixolonPrinter _Printer;

        public static BixolonPrinter Printer
        {
            get
            {
                if (_Printer == null)
                    _Printer = new BixolonPrinter();
                return _Printer;
            }
        }

        private Win32PrintClass _ComPrinter;

        private BixolonPrinter()
        {
            _ComPrinter = new Win32PrintClass();
            _ComPrinter.SetPrinterName("BIXOLON SRP-350");
        }


        #region IPrinter Members

        public void OpenCashDrawer()
        {
            // Open CashDrawer
            _ComPrinter.OpenCashdrawer(2);	// 2 pin cashdrawer
            _ComPrinter.OpenCashdrawer(5);	// 5 pin cashdrawer			
        }

        public void ChangeFont(string fontName, float fontSize, bool bold)
        {
            _ComPrinter.SetDeviceFont(fontSize, fontName, bold, false);
        }

        public void ChangeAlignment(Alignment alignment)
        {
            _ComPrinter.SetDeviceFont(9.5f, "FontControl", false, false);
            switch (alignment)
            {
                case Alignment.Center:
                    _ComPrinter.PrintText("x");
                    break;
                case Alignment.Left:
                    _ComPrinter.PrintText("w");
                    break;
                case Alignment.Rigth:
                    _ComPrinter.PrintText("y");
                    break;
                default:
                    break;
            }
        }

        public void PrintString(string value)
        {
            _ComPrinter.PrintText(value);
        }

        public void PrintImage(string imagePath)
        {
            _ComPrinter.PrintImage(imagePath);
        }

        public void CutReceipt()
        {
            _ComPrinter.SetDeviceFont(9.5f, "FontControl", false, false);
            _ComPrinter.PrintText("g");
        }

        public void Flush()
        {
            // Print
            _ComPrinter.EndDoc();
        }

        #endregion
    }
}
